package com.ruoyi.web.controller.his;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.HisCheck;
import com.ruoyi.his.service.IHisCheckService;
import com.ruoyi.his.service.IHisCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shebin
 * @site www.694840063@qq.com
 * @company 扬州绘鑫勤商贸有限公司
 * @create 2021-08-21 13:07
 */
@RestController
@RequestMapping("/his/check")
public class hisCheckController extends BaseController {

    @Autowired
    private IHisCheckService hisCheckService;

    /**
     * 获取检查费列表
     * @param check
     * @return
     */
    @PreAuthorize("@ss.hasPermi('his:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisCheck check){
        startPage();
        List<HisCheck> list = hisCheckService.selectCheckList(check);
        return getDataTable(list);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:check:query')")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable Long checkId)
    {
        return AjaxResult.success(hisCheckService.selectCheckById(checkId));
    }

    /**
     * 新增检查费
     */
    @PreAuthorize("@ss.hasPermi('his:check:add')")
    @Log(title = "检查费管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HisCheck check)
    {
        check.setCreateBy(getUsername());
        return toAjax(hisCheckService.insertCheck(check));
    }

    /**
     * 修改检查费
     */
    @PreAuthorize("@ss.hasPermi('his:check:edit')")
    @Log(title = "检查费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody HisCheck check)
    {
        check.setUpdateBy(getUsername());
        return toAjax(hisCheckService.updateCheck(check));
    }

    /**
     * 删除检查费
     */
    @PreAuthorize("@ss.hasPermi('his:check:remove')")
    @Log(title = "检查费管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds){
        return toAjax(hisCheckService.deleteCheckByIds(checkIds));
    }

    @Log(title = "检查费管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('his:check:export')")
    @GetMapping("/export")
    public AjaxResult export(HisCheck check)
    {
        List<HisCheck> list = hisCheckService.selectCheckList(check);
        ExcelUtil<HisCheck> util = new ExcelUtil(HisCheck.class);
        return util.exportExcel(list, "检查费数据");
    }
}
